/**********************************************************************************************************************************

"Foreign Aid and State Legitimacy: Evidence on Chinese and US Aid to Africa from Surveys, Survey Experiments, and Behavioral Games"
Robert A. Blair and Philip Roessler
World Politics
Replication Files

**********************************************************************************************************************************/

				
	
		clear
		clear matrix
		set more off
				
				
				
	// Set directory
					
		cd "[YOUR DIRECTORY]"

		
	
	// Load data
	
		use "survey_urban_data", clear
					
			
		
	// Define globals
		
		gl i_ctrls_fixed i_female i_age rel_Muslim 

		gl i_ctrls i_female i_age educ_abc educ_jh educ_hs employed rel_Muslim house_qual
		
		
		
		
xxx
  

	
	// Replicate figure 2, top panel
		
		reg itaxcomp_index_dum i.pstreat_alt $i_ctrls, cl(towncode)
			margins, atmeans at(pstreat_alt=(1(1)4)) level(95) post					
				
				test (_b[1._at] - _b[2._at]) = 0			
				test (_b[1._at] - _b[4._at]) = 0			
				test (_b[2._at] - _b[3._at]) = 0			
				test (_b[3._at] - _b[4._at]) = 0			
				
				graph set window fontface "Times"
				marginsplot, recast(scatter) graphr(color(white)) plotopts(mcolor(black) msymbol(square)) ciopts(lcolor(black) lpattern(solid)) ///
					title("Urban survey sample", color(black) position(1)) ///
					xtitle("Treatment group", margin(medium)) xlabel(, angle(horizontal)) xscale(range(0.5(1)4.5)) ///
					ytitle("Index of perceived obligation to pay taxes", margin(medsmall) size(medium)) ylabel(0(1)4) ///
					xsize(4.4) ysize(3.26)
					gr_edit .xaxis1.edit_tick 5 1 `"(N = 41)"', tickset(major) editstyle(tickstyle(textgap(4.6944)) )
					gr_edit .xaxis1.edit_tick 6 2 `"(N = 62)"', tickset(major) editstyle(tickstyle(textgap(4.6944)) )
					gr_edit .xaxis1.edit_tick 7 3 `"(N = 39)"', tickset(major) editstyle(tickstyle(textgap(4.6944)) )
					gr_edit .xaxis1.edit_tick 8 4 `"(N = 47)"', tickset(major) editstyle(tickstyle(textgap(4.6944)) )
			graph export "figure2_top.png", as(png) replace

		
		
	// Replicate table 2, top panel
							
		reg igov_support_index ichina_user iusa_user ichina_worker iusa_worker $i_ctrls_fixed, cl(towncode)
			outreg2 using "table2_top.tex", tex lab aster(se) dec(2) keep(ichina_user iusa_user ichina_worker iusa_worker) nocons append

		foreach y of varlist demoliberia_satis refusetopay_yes taxauthoritypay_agree avoidpaytax_easy {
			reg `y' ichina_user iusa_user ichina_worker  iusa_worker $i_ctrls_fixed, robust cl(towncode)
			outreg2 using "table2_top.tex", tex lab aster(se) dec(2) keep(ichina_user iusa_user ichina_worker iusa_worker) nocons append
				}	

	

	
    // Replicate table A1, right panel
  	   
		preserve
		
		gl summstats ichinaprojects iusaprojects ichinause iusause ichinawork iusawork ichinaworkfriend iusaworkfriend ///
			igov_support_index demoliberia_satis refusetopay_yes taxauthoritypay_agree avoidpaytax_easy ///
			iobbad_agree iobpoor_agree iobeat_agree iobdonors_agree
	   
		order $summstats
			outreg2 using "tableA1_right.tex", replace sum(log) keep($summstats) eqkeep(mean sd N) dec(2) tex label 

		restore
		
	
	
	
	
	
    // Replicate table A2, left panel
		
		preserve
		
		gl summstats i_age i_female rel_Christian educ_abc educ_hs farmer
	   
		order $summstats
			outreg2 using "tableA2_left.tex", replace sum(log) keep($summstats) eqkeep(mean sd N) dec(2) tex label 

		restore
	
	
	
	
		
    // Replicate table A5
										
		mlogit pstreat_alt $i_ctrls, cl(towncode)
			margins, dydx(*) predict(outcome(Control)) post
				outreg2 using "tableA5.tex", tex aster(se) dec(2) nocons ctitle(Control) label replace
		
		mlogit pstreat_alt $i_ctrls, cl(towncode)
			margins, dydx(*) predict(outcome(Government)) post
				outreg2 using "tableA5.tex", tex aster(se) dec(2) nocons ctitle(Government) label append
		
		mlogit pstreat_alt $i_ctrls, cl(towncode)
			margins, dydx(*) predict(outcome(China)) post
				outreg2 using "tableA5.tex", tex aster(se) dec(2) nocons ctitle(China) label append
		
		mlogit pstreat_alt $i_ctrls, cl(towncode)
			margins, dydx(*) predict(outcome(USA)) post
				outreg2 using "tableA5.tex", tex aster(se) dec(2) nocons ctitle(USA) label append
				
	
	
	
	
	
	
	
	
	
